]> wirehaze git hosting - BOS.git/blob - kernel/testkernels etc/vga.inc

wirehaze git hosting

Merge commit 'dba047e616f303ce818ba9ac7fb9f8a18a3717d3'
[BOS.git] / kernel / testkernels etc / vga.inc
1 ;----------------------------------------------------------;
2 ; BOS 0.04 Christoffer Bubach, 2004-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; VGA functions. Change video mode etc. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9
10 ;-------------------;
11 ; VGA palettes ;
12 ;-------------------;
13
14 palette256 db 00, 00, 00, 00, 10, 41, 12, 28, 18, 02, 43, 22, 35
15 db 19, 09, 58, 00, 00, 57, 35, 12, 43, 43, 47, 24, 24
16 db 28, 20, 24, 60, 10, 60, 15, 31, 47, 63, 62, 56, 20
17 db 60, 56, 22, 63, 61, 36, 63, 63, 63, 00, 00, 00, 05
18 db 05, 05, 08, 08, 08, 11, 11, 11, 14, 14, 14, 17, 17
19 db 17, 20, 20, 20, 24, 24, 24, 28, 28, 28, 32, 32, 32
20 db 36, 36, 36, 40, 40, 40, 45, 45, 45, 50, 50, 50, 56
21 db 56, 56, 63, 63, 63, 13, 12, 15, 15, 16, 22, 17, 20
22 db 29, 19, 24, 36, 21, 28, 43, 23, 31, 50, 25, 34, 57
23 db 26, 42, 63, 00, 15, 02, 01, 22, 04, 02, 29, 06, 03
24 db 36, 08, 04, 43, 10, 05, 50, 12, 06, 57, 14, 20, 63
25 db 40, 18, 06, 07, 25, 12, 11, 33, 17, 14, 40, 23, 18
26 db 48, 28, 21, 55, 34, 25, 62, 39, 27, 63, 48, 36, 15
27 db 03, 02, 22, 06, 04, 29, 09, 06, 36, 12, 08, 43, 15
28 db 10, 50, 18, 12, 57, 21, 14, 63, 28, 20, 15, 00, 00
29 db 22, 07, 00, 29, 15, 00, 36, 23, 00, 43, 31, 00, 50
30 db 39, 00, 57, 47, 00, 63, 55, 00, 15, 05, 03, 22, 11
31 db 07, 29, 17, 11, 36, 23, 15, 43, 29, 19, 50, 35, 23
32 db 57, 41, 27, 63, 53, 34, 28, 14, 12, 33, 20, 14, 38
33 db 26, 16, 43, 32, 18, 48, 38, 20, 53, 44, 22, 58, 50
34 db 24, 63, 56, 30, 05, 05, 06, 10, 10, 13, 15, 15, 20
35 db 20, 20, 27, 25, 25, 34, 30, 30, 41, 35, 35, 48, 44
36 db 44, 63, 03, 06, 05, 05, 11, 09, 07, 16, 13, 09, 21
37 db 17, 11, 26, 21, 13, 31, 25, 15, 36, 29, 20, 48, 38
38 db 06, 06, 07, 13, 13, 15, 20, 20, 23, 27, 27, 31, 34
39 db 34, 39, 41, 41, 47, 48, 48, 55, 57, 57, 63, 06, 15
40 db 04, 12, 22, 08, 18, 29, 12, 24, 36, 16, 30, 43, 20
41 db 36, 50, 24, 42, 57, 28, 54, 63, 35, 15, 10, 10, 22
42 db 16, 16, 29, 21, 21, 36, 27, 27, 43, 32, 32, 50, 38
43 db 38, 57, 43, 43, 63, 54, 54, 15, 15, 06, 22, 22, 12
44 db 29, 29, 18, 36, 36, 24, 43, 43, 30, 50, 50, 36, 57
45 db 57, 42, 63, 63, 54, 02, 04, 14, 06, 12, 21, 10, 20
46 db 28, 14, 28, 35, 18, 36, 42, 22, 44, 49, 26, 52, 56
47 db 36, 63, 63, 18, 04, 14, 24, 08, 21, 31, 12, 28, 37
48 db 16, 35, 44, 20, 42, 50, 24, 49, 57, 28, 56, 63, 38
49 db 63, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
50 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 53, 44, 22, 09
51 db 08, 12, 16, 14, 16, 22, 21, 20, 29, 27, 24, 35, 34
52 db 28, 42, 40, 32, 48, 47, 36, 57, 56, 43, 08, 12, 16
53 db 14, 16, 22, 21, 20, 29, 27, 24, 35, 34, 28, 42, 40
54 db 32, 48, 47, 36, 57, 56, 43, 63, 13, 09, 11, 21, 16
55 db 15, 27, 22, 18, 36, 29, 22, 42, 35, 25, 51, 42, 29
56 db 57, 48, 32, 63, 56, 39, 06, 14, 09, 12, 21, 14, 18
57 db 27, 22, 24, 33, 28, 30, 39, 36, 36, 46, 42, 42, 52
58 db 47, 50, 59, 53, 00, 00, 00, 00, 00, 00, 00, 00, 00
59 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
60 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
61 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
62 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
63 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
64 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
65 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
66 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
67 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
68 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
69 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
70 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
71 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
72 db 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
73 db 00
74
75 palette16 db 00, 00, 00, 00, 00, 42, 00, 42, 00, 00, 42, 42, 42
76 db 00, 00, 42, 00, 42, 42, 21, 00, 42, 42, 42, 21, 21
77 db 21, 21, 21, 63, 21, 63, 21, 21, 63, 63, 63, 21, 21
78 db 63, 21, 63, 63, 63, 21, 63, 63, 63
79
80 ;---------------------;
81 ; VGA mode values. ;
82 ;---------------------;
83 mode0x03 db 0x67, 0x00, 0x03, 0x00, 0x03, 0x00, 0x02, 0x5F, 0x4F
84 db 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, 0x4F, 0x0E
85 db 0x0F, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x0E, 0x8F, 0x28
86 db 0x01, 0x96, 0xB9, 0xA3, 0xFF, 0x00, 0x00, 0x00, 0x00
87 db 0x00, 0x10, 0x0E, 0x00, 0xFF, 0x00, 0x01, 0x02, 0x03
88 db 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B, 0x3C
89 db 0x3D, 0x3E, 0x3F, 0x0C, 0x00, 0x0F, 0x08, 0x00
90
91 mode0x13 db 0x63, 0x00, 0x03, 0x01, 0x0F, 0x00, 0x0E, 0x5F, 0x4F
92 db 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F, 0x00, 0x41, 0x00
93 db 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x0E, 0x8F, 0x28
94 db 0x40, 0x96, 0xB9, 0xA3, 0xFF, 0x00, 0x00, 0x00, 0x00
95 db 0x00, 0x40, 0x05, 0x0F, 0xFF, 0x00, 0x01, 0x02, 0x03
96 db 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C
97 db 0x0D, 0x0E, 0x0F, 0x41, 0x00, 0x0F, 0x00, 0x00
98
99
100 vga_buff dd 0
101
102 ;---------------------------------;
103 ; sets the screen to mode 0x03 ;
104 ;---------------------------------;
105 set_mode_0x03:
106 pushad
107 push ax
108
109 mov esi, mode0x03
110 call set_regs
111
112 call load_font ; IT WORKS!! FINALLY!
113
114 mov esi, palette16
115 call set_palette16
116
117 pop ax
118 cmp ax, 1
119 jne .cont
120 call cls ; in text.inc
121 .cont:
122
123 popad
124 ret
125
126
127
128 ;---------------------------------;
129 ; sets the screen to mode 0x13 ;
130 ;---------------------------------;
131 set_mode_0x13:
132 pushad
133 push ax
134
135 mov esi, mode0x13
136 call set_regs
137
138 mov esi, palette256
139 call set_palette256
140
141 pop ax
142 cmp ax, 1
143 jne .cont
144 mov edi, 0xa0000 ; write directly to mem
145 mov ax, 0x0000 ; clear all 256kb with color 0
146 mov ecx, 0x20000 ; 256kb, 0x20000 = (256*1024)/2
147 rep stosw ; by wordwrites
148 .cont:
149
150 popad
151 ret
152
153
154
155 ;----------------------------;
156 ; loads the standard font ;
157 ;----------------------------;
158 load_font:
159 cld
160 mov edi, vga_buff
161
162 mov dx, 0x03ce ; graphics
163 mov al, 5 ; write mode reg
164 out dx, al
165 inc dx
166 in al, dx
167 stosb
168 and al, 0xfc
169 xchg al, ah
170 mov al, 5
171 dec dx
172 out dx, ax
173
174 mov al, 6 ; misc reg
175 out dx, al
176 inc dx
177 in al, dx
178 stosb
179 and al, 0xf1
180 or al, 4
181 xchg al, ah
182 mov al, 6
183 dec dx
184 out dx, ax
185
186 mov dx, 0x03c4 ; sequencer port
187 mov al, 2 ; map mask reg
188 out dx, al
189 inc dx
190 in al, dx
191 stosb
192
193 dec dx
194 mov ax, 0x0402
195 out dx, ax
196
197 mov al, 4 ; memory selector reg
198 out dx, al
199 inc dx
200 in al, dx
201 stosb
202 or al, 4
203 xchg al, ah
204 mov al, 4
205 dec dx
206 out dx, ax
207
208 mov esi, font_8x16 ; font pointer
209 mov edi, 0xa0000
210
211 xor ecx, ecx
212 mov ebx, ecx
213
214 .l1:
215 mov cl, 16 ; font bytes (16 is standard)
216 rep movsb
217
218 mov cl, 32
219 sub cl, 16 ; font bytes
220 xor eax, eax
221 rep stosb
222
223 dec bl ; 256 chars
224 jnz .l1
225
226 mov esi, vga_buff
227
228 mov dx, 0x03ce
229 lodsb
230 xchg al, ah
231 mov al, 5
232 out dx, ax
233
234 lodsb
235 xchg al, ah
236 mov al, 6
237 out dx, ax
238
239 mov dx, 0x03c4
240 lodsb
241 xchg al, ah
242 mov al, 2
243 out dx, ax
244
245 lodsb
246 xchg al, ah
247 mov al, 4
248 out dx, ax
249
250 ret
251
252
253
254 ;------------------------------------;
255 ; put a pixel at x, y with color ;
256 ; used only in mode 0x13 ;
257 ; ;
258 ; input: bx = x ;
259 ; cx = y ;
260 ; al = color ;
261 ; ;
262 ; output: none. ;
263 ;------------------------------------;
264 put_0x13_pixel:
265 push ax
266 push bx
267 push cx
268 push edi
269
270 mov edi, 0xa0000 ; directly to mem
271 add di, bx
272 mov bx, cx
273 shl cx, 8
274 shl bx, 6
275 add cx, bx
276 add di, cx
277 stosb
278
279 pop edi
280 pop cx
281 pop bx
282 pop ax
283 ret
284
285
286 ;-----------------------------------------------------;
287 ; put a sprite at x, y. only for mode 0x13 ;
288 ; ;
289 ; input: ax = x, bx = y, cx = width, dx = height ;
290 ; esi = pointer to sprite ;
291 ; ;
292 ; output: none. ;
293 ;-----------------------------------------------------;
294 put_0x13_sprite:
295 pushad ; this was a
296 .row_loop: ; nightmare to write.
297 dec dx ; guess how many times
298 push cx ; i got lost in the push
299 push ax ; and pops here.. ;)
300 .col_loop: ; not to mention what
301 dec cx ; time it was when i wrote
302 push ax ; it.. :P
303 push bx
304 push cx
305 mov cx, bx
306 mov bx, ax
307 lodsb
308 call put_0x13_pixel
309 pop cx
310 pop bx
311 pop ax
312 inc ax
313 cmp cx, 0
314 jne .col_loop
315 pop ax
316 pop cx
317 inc bx
318 cmp dx, 0
319 jne .row_loop
320 popad
321 ret
322
323
324 ;---------------------------------------------;
325 ; sets the palette (256 colors) ;
326 ; ;
327 ; input: esi = palette. ;
328 ; output: none. ;
329 ;---------------------------------------------;
330 set_palette256:
331 push ax
332 push cx
333 push dx
334
335 xor cx, cx
336 .l1:
337 mov dx, 0x03C8
338 mov al, cl ; color no. = loop no.
339 out dx, al
340 inc dx ; port 0x3C9
341 mov al, byte [esi] ; red
342 out dx, al
343 inc esi
344 mov al, byte [esi] ; green
345 out dx, al
346 inc esi
347 mov al, byte [esi] ; blue
348 out dx, al
349 inc esi
350
351 inc cx
352 cmp cx, 256
353 jl .l1
354
355 pop dx
356 pop cx
357 pop ax
358 ret
359
360
361 ;---------------------------------------------;
362 ; sets the palette (16 colors) ;
363 ; ;
364 ; input: esi = pointer to palette. ;
365 ; output: none. ;
366 ;---------------------------------------------;
367 set_palette16:
368 push ax
369 push cx
370 push dx
371
372 xor cx, cx
373 .l1:
374 mov dx, 0x3DA
375 in al, dx
376 mov al, cl ; color no.
377 mov dx, 0x3C0
378 out dx, al
379 inc dx ; port 0x3C1
380 in al, dx
381 mov dx, 0x3C8
382 out dx, al
383
384 inc dx ; port 0x3C9
385 mov al, byte [esi] ; red
386 out dx, al
387 inc esi
388 mov al, byte [esi] ; green
389 out dx, al
390 inc esi
391 mov al, byte [esi] ; blue
392 out dx, al
393 inc esi
394
395 inc cx
396 cmp cx, 16
397 jl .l1
398
399 mov dx, 0x3DA
400 in al, dx
401 mov al, 0x20
402 mov dx, 0x3C0
403 out dx, al
404
405 pop dx
406 pop cx
407 pop ax
408 ret
409
410
411
412 ;---------------------------------;
413 ; Set VGA regs to choosen mode ;
414 ; internal use. ;
415 ;---------------------------------;
416 set_regs:
417 cli
418 mov dx, 0x3C2
419 lodsb
420 out dx, al
421
422 mov dx, 0x3DA
423 lodsb
424 out dx, al
425
426 xor ecx, ecx
427 mov dx, 0x3C4
428 .l1:
429 lodsb
430 xchg al, ah
431 mov al, cl
432 out dx, ax
433 inc ecx
434 cmp cl, 4
435 jbe .l1
436
437 mov dx, 0x3D4
438 mov ax, 0x0E11
439 out dx, ax
440
441 xor ecx, ecx
442 mov dx, 0x3D4
443 .l2:
444 lodsb
445 xchg al, ah
446 mov al, cl
447 out dx, ax
448 inc ecx
449 cmp cl, 0x18
450 jbe .l2
451
452 xor ecx, ecx
453 mov dx, 0x3CE
454 .l3:
455 lodsb
456 xchg al, ah
457 mov al, cl
458 out dx, ax
459 inc ecx
460 cmp cl, 8
461 jbe .l3
462
463 mov dx, 0x3DA
464 in al, dx
465
466 xor ecx, ecx
467 mov dx, 0x3C0
468 .l4:
469 in ax, dx
470 mov al, cl
471 out dx, al
472 lodsb
473 out dx, al
474 inc ecx
475 cmp cl, 0x14
476 jbe .l4
477
478 mov al, 0x20
479 out dx, al
480
481 sti
482 ret